﻿using Sc.Domain;
using Sc.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;

namespace Sc.Web.Controllers
{
    public class CarAuditController : BaseController
    {
        // GET: CarAudit
        public ActionResult Index()
        {
            ViewData["olist"] = CommService.GetOrgzByUserPer(UserLogin.UserId, 3);
            return View();
        }

        /// <summary>
        /// 获取检查列表
        /// </summary>
        /// <param name="pageSize">每页显示条数</param>
        /// <param name="pageIndex">当前页</param>
        /// <returns></returns>
        public JsonResult GetPageData(int pageSize, int pageIndex)
        {
            var orgz = Convert.ToInt32(Request.Params["orgz"]);
            var start = Request.Params["start"];
            var end = Request.Params["end"];
            var carNo = Request.Params["carNo"];
            var data = new CarAuditService().GetList(orgz, pageSize, pageIndex, start, end, carNo);
            return Json(data, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 创建车辆报废
        /// </summary>
        /// <returns></returns>
        public ActionResult CreateCarAudit()
        {
            ViewData["olist"] = CommService.GetOrgzByUserPer(UserLogin.UserId, 3);
            ViewData["type"] = new BaseItemService().GetListByType(10);
            return View();
        }
        /// <summary>
        /// 数据保存
        /// </summary>
        /// <returns></returns>
        public int SaveCarAudit()
        {
            string data = Request.Params["data"];
            JavaScriptSerializer json = new JavaScriptSerializer();
            CarAudit ent = json.Deserialize<CarAudit>(data);
            ent.UserId = UserLogin.UserId;
            //IList<Sys_Attachments> list = new List<Sys_Attachments>();
            //for (int i = 0; i < filePaths.Length; i++)
            //{
            //    if (!string.IsNullOrEmpty(filePaths[i]))
            //    {
            //        Sys_Attachments att = new Sys_Attachments();
            //        att.FileName = "车辆报废图片";
            //        att.FileUrl = filePaths[i];
            //        att.ObjectName = "CSRP";
            //        list.Add(att);
            //    }
            //}
            return new CarAuditService().Add(ent);
        }
        /// <summary>
        /// 修改报废信息
        /// </summary>
        /// <returns></returns>
        public ActionResult UpdateCarAudit()
        {
            int id = Convert.ToInt32(Request.Params["id"]);
            ViewData["ent"] = new CarAuditService().GetModel(id);
            ViewData["olist"] = CommService.GetOrgzByUserPer(UserLogin.UserId, 3);
            ViewData["type"] = new BaseItemService().GetListByType(10);
            return View();
        }
        /// <summary>
        /// 查看详情
        /// </summary>
        /// <returns></returns>
        public ActionResult CarAuditDetail()
        {
            int id = Convert.ToInt32(Request.Params["id"]);
            ViewData["ent"] = new CarAuditService().GetModel(id);
            return View();
        }
        /// <summary>
        /// 删除附件
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DeleteSysAttachments(int id)
        {
            return new Sys_AttachmentsService().DeleteSys_Attachments(id);
        }
        /// <summary>
        /// 报废信息删除
        /// </summary>
        /// <param name="ids">业务Id集合</param>
        /// <returns></returns>
        public int DeleteCarAudit(string ids)
        {
            return new CarAuditService().DeleteList(ids) ? 1 : 0;
        }
    }
}